import { addStationCollect, delStationCollect } from '@/service/apis/station';
import { getUserId } from '@/mixins/info';
import { toast } from '@/utils/util'

export const stationCollect = (item: any, page?: string) => {
  const userId = getUserId();
  if (!userId) {
    uni.navigateTo({
      url: page ? `/pages/login/login?page=${page}` : `/pages/login/login`,
    });
    return;
  }
  if (item.collectStatus) {
    delStationCollect({
      stationId: item.id,
    }).then((res) => {
      item.collectStatus = !item.collectStatus;
      toast('取消收藏成功');
    })
  } else {
    addStationCollect({
      stationId: item.id,
    }).then((res) => {
      item.collectStatus = !item.collectStatus;
      toast('收藏成功');
    })
  }
};